#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import shutil
import sys

execfile(os.path.join(sys.path[0], "framework.py"))

from oriolus.trotter.trotter import TrotterFactory
from unittest import TestCase, TestLoader, TextTestRunner, TestSuite

class TestInit(TestCase):
    wget_path = ';' + os.path.abspath("../../../etc/Windows")
    trotter_workdir = "./testdata/bala-bala"

    def setUp(self):
        self.env = os.getenv('PATH')
        os.putenv('PATH', self.env + self.wget_path)

    def tearDown(self):
        if os.path.exists(os.path.abspath(self.trotter_workdir)):
            shutil.rmtree(self.trotter_workdir)

    def test_trotter_factory_get_trotter1(self):
        factory = TrotterFactory()
        trotter = factory.get_trotter({})

        self.assertNotEqual(None, trotter)
        self.assertEqual(".trotter", os.path.basename(trotter.get_output_path()))

    def test_trotter_factory_get_trotter2(self):
        factory = TrotterFactory()
        trotter = factory.get_trotter({'workdir':self.trotter_workdir})

        self.assertNotEqual(None, trotter)
        self.assertEqual("bala-bala", os.path.basename(trotter.get_output_path()))

if __name__ == "__main__":
    suite = TestLoader().loadTestsFromTestCase(TestInit)
    alltests = TestSuite(suite)
    TextTestRunner(verbosity=2).run(alltests)